﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region SYS_PrivilegeItem实体类
public class SYS_PrivilegeItem
{
	private string m_PrivilegeID;
	private string m_ObjectID;
	private string m_ActionCode;
	private string m_ObjectType;
	
	public SYS_PrivilegeItem ()
	{
		m_PrivilegeID="";
		m_ObjectID="";
		m_ActionCode="";
		m_ObjectType="";
	}
	
	public string PrivilegeID
	{
		get{return m_PrivilegeID;}
		set{m_PrivilegeID=value;}
	}
	public string ObjectID
	{
		get{return m_ObjectID;}
		set{m_ObjectID=value;}
	}
	public string ActionCode
	{
		get{return m_ActionCode;}
		set{m_ActionCode=value;}
	}
	public string ObjectType
	{
		get{return m_ObjectType;}
		set{m_ObjectType=value;}
	}
}
#endregion

#region SYS_PrivilegeItem管理类
public partial class LogicLayer
{
	public bool AddSYS_PrivilegeItem(SYS_PrivilegeItem theSYS_PrivilegeItem)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into SYS_PrivilegeItem (PrivilegeID,ObjectID,ActionCode,ObjectType) values (@PrivilegeID,@ObjectID,@ActionCode,@ObjectType)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@PrivilegeID", DbType.String, theSYS_PrivilegeItem.PrivilegeID);
			db.AddInParameter(cmd, "@ObjectID", DbType.String, theSYS_PrivilegeItem.ObjectID);
			db.AddInParameter(cmd, "@ActionCode", DbType.String, theSYS_PrivilegeItem.ActionCode);
			db.AddInParameter(cmd, "@ObjectType", DbType.String, theSYS_PrivilegeItem.ObjectType);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddSYS_PrivilegeItem:" + ex.Message );
			return false;
		}
	}
	
	public SYS_PrivilegeItem GetSYS_PrivilegeItemFromDataReader(IDataReader dataReader)
	{
		try
		{
			SYS_PrivilegeItem result = new SYS_PrivilegeItem();
			
			if (dataReader["PrivilegeID"] != null && dataReader["PrivilegeID"] != System.DBNull.Value )
				result.PrivilegeID = (string)dataReader["PrivilegeID"];
			if (dataReader["ObjectID"] != null && dataReader["ObjectID"] != System.DBNull.Value )
				result.ObjectID = (string)dataReader["ObjectID"];
			if (dataReader["ActionCode"] != null && dataReader["ActionCode"] != System.DBNull.Value )
				result.ActionCode = (string)dataReader["ActionCode"];
			if (dataReader["ObjectType"] != null && dataReader["ObjectType"] != System.DBNull.Value )
				result.ObjectType = (string)dataReader["ObjectType"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderSYS_PrivilegeItem:" + ex.Message);
			return null;
		}
	}
	
	public SYS_PrivilegeItem GetSYS_PrivilegeItem(string PrivilegeID,string ObjectID,string ActionCode)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From SYS_PrivilegeItem where PrivilegeID=@PrivilegeID and ObjectID=@ObjectID and ActionCode=@ActionCode";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@PrivilegeID", DbType.String, PrivilegeID);
			db.AddInParameter(cmd, "@ObjectID", DbType.String, ObjectID);
			db.AddInParameter(cmd, "@ActionCode", DbType.String, ActionCode);
			
			SYS_PrivilegeItem result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetSYS_PrivilegeItemFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetSYS_PrivilegeItem:" + ex.Message);
			return null;
		}
	}
	
	public bool DelSYS_PrivilegeItem(string PrivilegeID,string ObjectID,string ActionCode)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From SYS_PrivilegeItem where PrivilegeID=@PrivilegeID and ObjectID=@ObjectID and ActionCode=@ActionCode";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@PrivilegeID", DbType.String, PrivilegeID);
			db.AddInParameter(cmd, "@ObjectID", DbType.String, ObjectID);
			db.AddInParameter(cmd, "@ActionCode", DbType.String, ActionCode);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelSYS_PrivilegeItem:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateSYS_PrivilegeItem(SYS_PrivilegeItem theSYS_PrivilegeItem)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update SYS_PrivilegeItem set ObjectType=@ObjectType where PrivilegeID=@PrivilegeID and ObjectID=@ObjectID and ActionCode=@ActionCode";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@ObjectType", DbType.String, theSYS_PrivilegeItem.ObjectType);
			db.AddInParameter(cmd, "@PrivilegeID", DbType.String, theSYS_PrivilegeItem.PrivilegeID);
			db.AddInParameter(cmd, "@ObjectID", DbType.String, theSYS_PrivilegeItem.ObjectID);
			db.AddInParameter(cmd, "@ActionCode", DbType.String, theSYS_PrivilegeItem.ActionCode);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateSYS_PrivilegeItem:" + ex.Message);
			return false;
		}
	}
	
	public List<SYS_PrivilegeItem> ListSYS_PrivilegeItem()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from SYS_PrivilegeItem";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<SYS_PrivilegeItem> result = new  List<SYS_PrivilegeItem>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					SYS_PrivilegeItem obj = GetSYS_PrivilegeItemFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListSYS_PrivilegeItem:" + ex.Message);
			return null;
		}
	}
	
}
#endregion